﻿using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using ZFSDomain.Common.CoreLib;
using ZFSDomain.Common.UserControls;
using ZFSDomain.View.User;
using ZFSDomain.ViewModel;
using ZFSDomain.ViewModel.Step;
using ZFSDomain.ViewModel.User;

namespace ZFSDomain
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Messenger.Default.Register<string>(this, "MainExit", Exit);
            Messenger.Default.Register<string>(this, "MinWindow", Min);
            Messenger.Default.Register<StateType>(this, "FullScreen", FullScreen);
            Messenger.Default.Register<bool>(this, "PackUp", PackUp);
        }

        /// <summary>
        /// 收起面板
        /// </summary>
        /// <param name="ischecked"></param>
        public void PackUp(bool ischecked)
        {
            MenuToggleButton.IsChecked = ischecked;
        }

        /// <summary>
        /// 最小化
        /// </summary>
        /// <param name="msg"></param>
        public void Min(string msg)
        {
            this.WindowState = WindowState.Minimized;
        }

        /// <summary>
        /// 关闭应用
        /// </summary>
        /// <param name="msg"></param>
        public async void Exit(string msg)
        {
            if (await Msg.Question(msg))
            {
                this.Close();
            }
        }

        /// <summary>
        /// 设置左侧面板状态
        /// </summary>
        /// <param name="type"></param>
        public void FullScreen(StateType type)
        {
            switch (type)
            {
                case StateType.Expand:
                    //StoryBoardPackUp(Left_Menu, Left_Menu.Width, 0, 300);
                    //StoryBoardPackUp(Top_Header, Top_Header.Height, 0, 300, "Height");
                    //StoryBoardPackUp(Left_MinMenu, Left_MinMenu.Width, 60, 300); 

                    break;
                case StateType.PackUp:
                    //StoryBoardExpand(Left_MinMenu, Left_MinMenu.Width, 0, 300);
                    //StoryBoardExpand(Left_Menu, Left_Menu.Width, 200, 300);
                    //StoryBoardPackUp(Top_Header, 0, 100, 300, "Height");
                    break;
            }
        }

        #region Animation 

        /// <summary>
        /// 展开动画
        /// </summary>
        /// <param name="dependency"></param>
        /// <param name="Width"></param>
        /// <param name="TimeSpan"></param>
        public static void StoryBoardPackUp(DependencyObject dependency, double Form, double To, int TimeSpan, string PropertyName = "Width")
        {
            System.Windows.Media.Animation.Storyboard sb = new System.Windows.Media.Animation.Storyboard();
            System.Windows.Media.Animation.DoubleAnimation dmargin = new System.Windows.Media.Animation.DoubleAnimation();
            dmargin.Duration = new TimeSpan(0, 0, 0, 0, TimeSpan);
            dmargin.From = Form;
            dmargin.To = To;
            System.Windows.Media.Animation.Storyboard.SetTarget(dmargin, dependency);
            System.Windows.Media.Animation.Storyboard.SetTargetProperty(dmargin, new PropertyPath(PropertyName, new object[] { }));
            sb.Children.Add(dmargin);
            sb.Begin();
        }

        /// <summary>
        /// 展开左侧面板
        /// </summary>
        private void StoryBoardExpand(DependencyObject dependency, double Form, double To, int TimeSpan, string PropertyName = "Width")
        {
            System.Windows.Media.Animation.Storyboard sb = new System.Windows.Media.Animation.Storyboard();
            System.Windows.Media.Animation.DoubleAnimation dmargin = new System.Windows.Media.Animation.DoubleAnimation();
            dmargin.Duration = new Duration(new TimeSpan(0, 0, 0, 0, TimeSpan));
            dmargin.From = Form;
            dmargin.To = To;
            System.Windows.Media.Animation.Storyboard.SetTarget(dmargin, dependency);
            System.Windows.Media.Animation.Storyboard.SetTargetProperty(dmargin, new PropertyPath(PropertyName, new object[] { }));
            sb.Children.Add(dmargin);
            sb.Begin();
        }

        #endregion

    }
}
